import logging
import yaml
import json
import requests
import time
import uuid
import subprocess

def get_config_value(config_file_path, variable_name, logger):
    ##############################
    # @description 读取yaml文件中的配置信息
    # @return variable_name对应的值
    ##############################
    with open(config_file_path, 'r', encoding='utf-8') as stream:
        try:
            config = yaml.safe_load(stream)
            if variable_name not in config:
                logger.info(f"变量 {variable_name} 不在文件 {config_file_path}中")
                return None
            return config[variable_name]
        except yaml.YAMLError as exc:
            logger.info(exc)
            return None

def setup_logger(log_output_file, log_level=logging.INFO):
    ##############################
    # @description 设置log库，将日志同时输出到文件和控制台(删除所有注释行可只输出到文件)
    ##############################
    logger = logging.getLogger(__name__)
    logger.setLevel(log_level)
    fh = logging.FileHandler(log_output_file)
    ch = logging.StreamHandler()  # 创建一个StreamHandler
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)  # 设置StreamHandler使用相同的日志格式
    logger.addHandler(fh)
    logger.addHandler(ch)  # 将StreamHandler添加到logger
    return logger
